﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Sunboxsoft.Common.Utility
{
    public class MD5Utility
    {
        public static string GetStringX(string source)
        {
            byte[] result = Encoding.UTF8.GetBytes(source);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            StringBuilder byte2String = new StringBuilder();

            for (int i = 0; i < output.Length; i++)
            {
                byte2String.Append(output[i].ToString("X"));
            }
            return byte2String.ToString();
        }

        public static string GetStringX2(string source)
        {
            byte[] result = Encoding.UTF8.GetBytes(source);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            StringBuilder byte2String = new StringBuilder();

            for (int i = 0; i < output.Length; i++)
            {
                byte2String.Append(output[i].ToString("X2"));
            }
            return byte2String.ToString();
        }
    }
}
